home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue39 / rogers_example05f.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-14  |  1.5 KB  |  70 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /*
  5.     This program is written to demonstrate the <stdlib.h> library.
  6.     This program will demonstrate environmental functions of the stdlib library.
  7.     Written by James M. Rogers
  8.     22 March 1999
  9.     Released to the Public Domain on this date.
  10. */
  11.  
  12. #define OVERWRITE 1
  13. #define NO_OVERWRITE 0
  14.  
  15. void shutdown_1 () {
  16.     printf("\nShutting down!\n\n");
  17. }
  18.  
  19. void shutdown_2 () {
  20.     printf("\nReally Shutting down!\n\n");
  21. }
  22.  
  23. void shutdown_3 () {
  24.     printf("\nReally Really Shutting down!\n\n");
  25. }
  26.  
  27. void shutdown_4 () {
  28.     printf("\nReally Really Really Shutting down!\n\n");
  29. }
  30.  
  31. main(){
  32.  
  33.     atexit(shutdown_4);
  34.  
  35.     printf("I am displaying the environmental variable TESTING : ");
  36.     printf("%s\n", getenv("TESTING"));
  37.  
  38.     printf("The following setenv will only set TESTING if TESTING is unset : ");
  39.     if ( setenv("TESTING", "no_overwite", NO_OVERWRITE) )  {
  40.     abort();
  41.     } else {
  42.     printf("%s\n", getenv("TESTING"));
  43.     }
  44.  
  45.     atexit(shutdown_3);
  46.  
  47.     printf("I am unsetting TESTING.\n");
  48.     unsetenv("TESTING");
  49.  
  50.     printf("The following setenv will only set TESTING if TESTING is unset : ");
  51.     if ( setenv("TESTING", "no_overwite", NO_OVERWRITE) )  {
  52.         abort();
  53.     } else {
  54.         printf("%s\n", getenv("TESTING"));
  55.     }
  56.  
  57.     atexit(shutdown_2);
  58.  
  59.     printf("The following setenv will always set TESTING : ");
  60.     if ( setenv("TESTING", "overwrite", OVERWRITE) ) {
  61.     abort();
  62.     } else {
  63.     printf("%s\n", getenv("TESTING"));
  64.     }
  65.  
  66.     atexit(shutdown_1);
  67.  
  68.     exit (0);
  69. }
  70.